const fs = require('fs')
const path = require('path')



fs.readFile(path.join(__dirname, 'data/data.json'), (err, data) => {
  if (err) {
    return console.log(err)
  } else {
    const list = JSON.parse(data.toString())
    const boyList = []
    const girlList = []

    list.forEach(obj => {
      if (obj.gender === '男') {
        boyList.push(obj)
      } else if (obj.gender === '女') {
        girlList.push(obj)
      }
    })

    fs.writeFile(path.join(__dirname, './classify/boy.json'), JSON.stringify(boyList), err => {
      console.log('已输入男性')

    })

    fs.writeFile(path.join(__dirname, './classify/girl.json'), JSON.stringify(girlList), err => {
      console.log('已输入女性')
    })
  }

})



